package org.hawk.gwt.ppc.parser.impl;

import java.util.List;

import org.hawk.gwt.ppc.parser.AnnotationDescriptor;
import org.hawk.gwt.ppc.parser.BlockDescriptor;
import org.hawk.gwt.ppc.parser.ClassDescriptor;
import org.hawk.gwt.ppc.parser.ConstructorDescriptor;
import org.hawk.gwt.ppc.parser.Descriptor;
import org.hawk.gwt.ppc.parser.FieldDescriptor;
import org.hawk.gwt.ppc.parser.MethodDescriptor;
import org.hawk.gwt.ppc.parser.Token;
/**
 * {@link ClassDescriptor} interface implementation for {@link ClassDescriptorParser}.
 * 
 * @author alex.bereznevatiy@gmail.com
 * 
 */
final class ClassDescriptorImpl extends AbstractDescriptorContainer implements
		ClassDescriptor {
	
	private ClassDescriptorType type;
	private String name;
	private List<String> modifiersList;
	private List<String> extendsList;
	private List<String> implementsList;
	private List<MethodDescriptor> methods;
	private List<BlockDescriptor> initilizers;
	private List<ConstructorDescriptor> constructors;
	private List<ClassDescriptor> declaredClasses;
	private List<FieldDescriptor> fields;

	ClassDescriptorImpl(ClassDescriptorType type, String name,
			List<Token> headTokens, Token lastToken, List<Descriptor> children,
			List<String> modifiersList, List<String> extendsList,
			List<String> implementsList, List<MethodDescriptor> methods,
			List<BlockDescriptor> initilizers,
			List<ConstructorDescriptor> constructors,
			List<ClassDescriptor> declaredClasses, 
			List<FieldDescriptor> fields,
			List<AnnotationDescriptor> annotations) {
		super(children);
		
		this.type = type;
		this.name = name;
		this.modifiersList = unmodify(modifiersList);
		this.extendsList = unmodify(extendsList);
		this.implementsList = unmodify(implementsList);
		this.methods = unmodify(methods);
		this.initilizers = unmodify(initilizers);
		this.constructors = unmodify(constructors);
		this.declaredClasses = unmodify(declaredClasses);
		this.fields = unmodify(fields);
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.ModificatedDescriptor#getModifiers()
	 */
	public List<String> getModifiers() {
		return modifiersList;
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.ClassDescriptor#getName()
	 */
	public String getName() {
		int index = name.indexOf('<');
		if (index < 0) {
			return name;
		}
		return name.substring(0, index);
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.ClassDescriptor#getType()
	 */
	public ClassDescriptorType getType() {
		return type;
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.ClassDescriptor#getTypeParameters()
	 */
	public String getTypeParameters() {
		int index = name.indexOf('<');
		if (index < 0) {
			return "";
		}
		return name.substring(index);
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.ClassDescriptor#getExtendsSection()
	 */
	public List<String> getExtendsSection() {
		return extendsList;
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.ClassDescriptor#getImplementsSection()
	 */
	public List<String> getImplementsSection() {
		return implementsList;
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.ClassDescriptor#getMethods()
	 */
	public List<MethodDescriptor> getMethods() {
		return methods;
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.ClassDescriptor#getInitializers()
	 */
	public List<BlockDescriptor> getInitializers() {
		return initilizers;
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.ClassDescriptor#getConstructors()
	 */
	public List<ConstructorDescriptor> getConstructors() {
		return constructors;
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.ClassDescriptor#getDeclaredClasses()
	 */
	public List<ClassDescriptor> getDeclaredClasses() {
		return declaredClasses;
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.ClassDescriptor#getFields()
	 */
	public List<FieldDescriptor> getFields() {
		return fields;
	}
}
